package com.cqeec.myblog.controller;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cqeec.myblog.model.Article;
import com.cqeec.myblog.service.ArticleService;
import com.cqeec.myblog.service.ArticleServiceImpl;

@WebServlet("/article/view.html")
public class ViewArticleServlet extends HttpServlet {
	private static final long serialVersionUID = -5480020672946943472L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = request.getParameter("id");
		// 从数据库中根据文章标识获取文章
		ArticleService articleService = new ArticleServiceImpl();
		try {
			Article article = articleService.getArticle(id);
			// 通过request将文章数据带到viewArticle.jsp页面中
			request.setAttribute("article", article);
			request.getRequestDispatcher("../viewArticle.jsp").forward(request, response);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}
